<!--
 * @Author: WeijianXu weijian.xu@unidt.com
 * @Date: 2024-03-12 19:57:09
 * @LastEditors: WeijianXu weijian.xu@unidt.com
 * @LastEditTime: 2024-03-14 10:18:54
 * @FilePath: \front-end-of-task-center\src\views\home\widgets\corporate-items.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="corporate-items">
    <el-input placeholder="请输入事项名称" v-model="keyword" class="corporate-items-input"
      @keyup.enter.native="handleQuery">
      <el-button slot="append" type="primary" @click="handleQuery">
        <svg-icon icon-class="search"></svg-icon>
      </el-button>
    </el-input>
    <ul class="corporate-items-list" v-loading="table.loading">
      <li v-for="item in table.data" class="corporate-items-list-item">
        <div class="list-hint">
          <span class="rhomboid-tag" :class="noticeStatus(item).color">
            <span>{{ noticeStatus(item).text }}</span>
          </span>
        </div>
        <!-- <div class="list-tag"><span class="ant-tag ant-tag-blue">财政支持</span></div> -->
        <div :title="item.title" class="list-title">{{ item.title }}</div>
        <div class="list-content" v-html="item.content.substring(0, 200)">
        </div>
        <div class="list-info">
          <span>发文日期：{{ parseTime(item.startTime, '{y}-{m}-{d}') }}</span>
          <span>浏览量：{{ item.count || 0 }}</span>
        </div>
        <div class="list-action">
          <div class="list-action-left">
            <div class="declare-date">
              <span>申报时间：{{ item.startTime }} 至 {{ item.endTime }}</span>
            </div>
          </div>
          <div class="list-declare">
            <el-button type="primary" size="small" :plain="noticeStatus(item).key === 'done'" @click="handleDeclare(item)">立即{{ noticeStatus(item).key === 'done' ? '查看' : '申报' }}</el-button>
          </div>
        </div>
      </li>
    </ul>

    <!-- 分页组件 -->
    <pagination v-show="table.total > 0" :total="table.total" :page.sync="table.page.pageNo"
      :limit.sync="table.page.pageSize" align="center" @pagination="handleQuery" />
  </div>
</template>

<script>
import { getEnterpriseList } from '@/api/enterprise/info';
export default {
  name: 'JxtWorkflowCorporateItems',

  data() {
    return {
      workflows: [
        {
          id: 1,
          name: 'Corporate Workflow',
          description: 'A basic workflow for corporate documents.',
          type: 'corporate',
          active: true,
        },
      ],

      keyword: '',

      table: {
        data: [],
        loading: false,
        total: 0,
        page: {
          pageNo: 1,
          pageSize: 10,
        },
      },
    };
  },
  activated() {
    this.handleQuery();
  },

  mounted() {
    this.handleQuery();
  },

  methods: {
    handleQuery() {
      // this.$emit('handleQuery', this.keyword);
      getEnterpriseList({
        title: this.keyword, type: 3,
        ...this.table.page,
      })
        .then((res) => {
          const { list, total } = res?.data || {};
          this.table.data = list || [];
          this.table.total = total || 0;
        })
        .finally(() => {
          this.table.loading = false;
        });
    },
    noticeStatus(info) {
      if (!info.startTime || !info.endTime) {
        return { text: '未知', color: 'info', rest: '' };
      }
      const start = new Date(info.startTime).getTime();
      const end = new Date(info.endTime).getTime();
      const now = Date.now();
      if (now < start) {
        return { key: 'todo', text: '待开始', color: 'warning' };
      }
      if (now >= end) {
        return {key: 'done', text: '已结束', color: 'info' };
      }
      return { key: 'doing', text: '进行中', color: 'default' };
    },

    handleDeclare(item) {
      this.$router.push({
        path: '/home/item-detail',
        query: {
          id: item.id,
        },
      })
    },
  },
};
</script>

<style lang="scss">
.corporate-items {
  text-align: center;
  margin-right: 10px;
  font-size: 14px;


  .corporate-items-input {
    width: 80%;
    max-width: 800px;
    height: 40px;
    margin: 10px auto 20px;

     .el-input__inner {
      height: 40px;
      line-height: 40px;
      font-size: 16px;
    }

    .el-input-group__append,
    .el-input-group__prepend {
      background-color: #1890ff;
      border-color: #1890ff;
    }

    .el-button {

      &.el-button--primary {
        color: #FFF;
        background-color: #1890ff;
      }
    }
  }

  &-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    height: 100%;
    background-color: #f4f6f9;
    border: 1px solid #f4f6f9;
    padding: 0;
    text-align: left;
    color: #000000;

    &-item {
      position: relative;
      margin-top: 20px;
      padding: 16px;
      width: 100%;
      background: #fff;
      box-shadow: 2px 2px 10px 0 rgba(72, 84, 105, .04);
      border-radius: 4px 0 4px 4px;
      box-sizing: border-box;
      overflow: hidden;

      &:first-child {
        margin-top: 0;
      }
    }

    .list-hint {
      position: absolute;
      right: -12px;
      top: 0;

      .rhomboid-tag {
        display: inline-block;
        margin-left: 10px;
        padding: 0 24px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background: #f1960d;
        -webkit-transform: skewX(40deg);
        transform: skewX(40deg);

        span {
          color: #fff;
          display: inline-block;
          -webkit-transform: skewX(-40deg);
          transform: skewX(-40deg);
        }

        &.info {
          background-color: #909399;
        }

        &.warning {
          background-color: #5e95c4;
        }
      }
    }

    .list-title {
      margin-top: 10px;
      line-height: 28px;
      width: 90%;
      font-size: 20px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      cursor: pointer;
    }

    .list-content {
      margin-top: 12px;
      line-height: 22px;
      font-size: 16px;
      color: #666;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      max-height: 3em;

      * {
        margin: 0;
        padding: 0;

        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
      }
    }

    .list-info {
      display: flex;
      justify-content: space-between;
      margin-top: 20px;
      margin-bottom: 20px;

      span {
        margin-right: 10px;
        width: 100%;
        color: #999;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }

    .list-action {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding-top: 16px;
      border-top: 1px solid #eee;

      &-left {
        flex: 1;
        display: flex;
        justify-content: space-between;
      }
    }

    .declare-date {
      line-height: 20px;
      color: #999;
      display: flex;
      align-items: center;
    }

    .list-declare {
      width: 130px;
      text-align: right;
    }
  }
}
</style>
